import event from '../../unit/event';
import states from '../states';

const down = (store) => {
	store.commit("key-reset", true);
	if (store.state.lock) {
		return;
	}
	console.log("restart", store.state.cur,store.state.reset,store.state.lock);
	let cb = function() {};
	if (store.state.cur !== null) {
		cb = function() {
			states.overStart();
		};
	} else {
		cb = function() {
			if (store.state.lock) {
				return;
			}
			states.start();
		};
	}
	event.down({
		key: 'r',
		once: true,
		callback: () => {
			cb && cb();
		},
	});
};

const up = (store) => {
	store.commit("key-reset", false);
	event.up({
		key: 'r',
	});
};

export default {
	down,
	up,
};
